<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>服务配置扫描器</title>
</head>
<body>
    <h1>扫描服务配置文件</h1>
    <button onclick="scanServices()">开始扫描</button>
    <div id="output"></div>

    <script>
        async function scanServices() {
            const output = document.getElementById('output');
            output.innerHTML = '<p>正在扫描服务文件...</p>';
            
            try {
                // 服务文件列表
                const serviceFiles = [
                    'add-friend.json', 'alarm-clock-close.json', 'alarm-clock-delete.json', 'alarm-clock-set.json',
                    'audio-dcschat-test.json', 'audio-listen.json', 'audio-listen-english.json', 'audio-oss.json',
                    'audio-point-read.json', 'audio-point-read-english.json', 'baidu-audio-generate.json',
                    'bullying-detection.json', 'bullying-notification.json', 'cache-clear.json', 'change-role-voice.json',
                    'chat-ai.json', 'composition-guidance.json', 'composition-revision.json', 'ctrl-change-voice-next.json',
                    'english-corner.json', 'essay-generate.json', 'functioncall-test.json', 'generate-image.json',
                    'image-generate.json', 'lesson-ai-chat.json', 'listen-music.json', 'longtext-audio.json',
                    'minimax-audio.json', 'oral-eval.json', 'oral-practice.json', 'prefer-setting.json',
                    'prompt-template.json', 'receive-message.json', 'replay-latest.json', 'report-generate.json',
                    'role-chat.json', 'role-setting.json', 'send-message.json', 'sensitive-check.json',
                    'speech-eval.json', 'speech-to-text.json', 'story.json', 'text-audio.json',
                    'text-optimizer.json', 'voice-call.json', 'voice-clone.json', 'volcengine-clone.json'
                ];

                const services = [];
                
                for (const filename of serviceFiles) {
                    try {
                        const response = await fetch(`services/${filename}`);
                        const data = await response.json();
                        
                        const commands = data.Cmds ? data.Cmds.map(cmd => cmd.Cmd).filter(cmd => cmd) : [];
                        const nodeCount = data.Cmds ? data.Cmds.length : 0;
                        
                        // 根据文件名推断分类
                        let category = 'other';
                        if (filename.startsWith('audio-')) category = 'audio';
                        else if (filename.startsWith('alarm-')) category = 'alarm';
                        else if (filename.startsWith('voice-')) category = 'voice';
                        else if (filename.startsWith('text-')) category = 'text';
                        else if (filename.startsWith('speech-')) category = 'speech';
                        else if (filename.startsWith('role-')) category = 'role';
                        else if (filename.startsWith('oral-')) category = 'oral';
                        else if (filename.startsWith('bullying-')) category = 'bullying';
                        else if (filename.startsWith('composition-')) category = 'composition';
                        else if (filename.startsWith('baidu-')) category = 'baidu';
                        
                        services.push({
                            name: data.Name || filename.replace('.json', ''),
                            filename: filename,
                            category: category,
                            commands: commands.slice(0, 10), // 只取前10个命令
                            nodes: nodeCount
                        });
                        
                    } catch (error) {
                        console.error(`Error loading ${filename}:`, error);
                    }
                }
                
                // 生成JavaScript数组代码
                const jsCode = `const servicesData = ${JSON.stringify(services, null, 2)};`;
                
                output.innerHTML = `
                    <h2>扫描完成！找到 ${services.length} 个服务</h2>
                    <h3>生成的JavaScript代码:</h3>
                    <textarea style="width: 100%; height: 400px; font-family: monospace;">${jsCode}</textarea>
                    <h3>分类统计:</h3>
                    <ul>
                        ${Object.entries(services.reduce((acc, s) => {
                            acc[s.category] = (acc[s.category] || 0) + 1;
                            return acc;
                        }, {})).map(([cat, count]) => `<li>${cat}: ${count}</li>`).join('')}
                    </ul>
                `;
                
            } catch (error) {
                output.innerHTML = `<p style="color: red;">扫描出错: ${error.message}</p>`;
            }
        }
    </script>
</body>
</html>
